package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 用户登录功能
 * 程序启动要求输入用户名和密码
 * 对比userinfo中是否存在此用户名
 */

public class LoginDemo {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎登录", "登录");
        try (Connection connection = DBUtil.getConnection()) {
            Statement satatement = connection.createStatement();
            String sql = "select username,password " +
                         "from userinfo " +
                    "where username =  '" + userInfo.getUsername() + "' and password = '" + userInfo.getPassword() + "'";
            System.out.println(sql);
            ResultSet resultSet = satatement.executeQuery(sql);
            if (resultSet.next()) {
                System.out.println("登陆成功");
            } else {





                System.out.println("用户名或密码错误");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
